<?php

namespace frontend\modules\business\controllers;

use yii;
use yii\web\Controller;

/**
 * Base controller for the `business` module
 */
class BaseController extends Controller
{
   
    //主库链接
    public $master = null;
    
    public function init()
    {
        parent::init();
        
        $masterConfig = $this->module->params['master'];
        
        $this->master = new yii\db\Connection([
            'dsn' => "mysql:host={$masterConfig['host']};dbname={$masterConfig['dbname']}",
            'username' => $masterConfig['username'],
            'password' => $masterConfig['password'],
            'charset' => $masterConfig['charset'],
            'tablePrefix' => $masterConfig['tablePrefix'],
        ]);
        
    }
    
    /**
     * 获取基本商户信息
     * 第一个参数：值
     * 第二个参数：字段名
     * 返回一条信息
     */
    protected function getBusinessInfo($business, $type = 'a.id')
    {
        
        if (!$business) {
            return null;
        }
        
        $where['a.del_status'] = 0;
        $where[$type] = $business;
        
        
        $business = (new \yii\db\Query())
        ->select(['a.weichat_id'])
        ->from('busy_admin_user as a')
        ->leftJoin(['b' => 'busy_admin_user_base'], 'b.id = a.id')
        ->where($where)
        ->one($this->master);
        
        return $business;
    }
    
    

}
